<template>
  <div class="add">
    <van-nav-bar
      fixed
      placeholder
      left-arrow
      @click-left="$router.back()"
      :title="`${$route.query.q}`"
    />
    <van-list
    class="search-list"
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <van-cell v-for="item in list" 
      :key="item.art_id" 
      :title="item.title" 
      @click="$router.push({path:'/myarticle',query:{id:item.art_id}})"
      />
    </van-list>
  </div>
</template>

<script>
import {getSearchList} from './home'
export default {
  name: "searchResult",
  data() {
    return {
      loading: false,
      finished: false,
      list: [],
      page:1
    };
  },
  methods: {
   async onLoad() {
      //加载数据
      let res = await getSearchList({
          page:this.page,
          per_page:10,
          q:this.$route.query.q
      })
      console.log(res);
      //绑定数据
      this.list.push(...res.data.data.results)
      //页码自增
      this.page++
      //关闭加载更多动画
      this.loading =false
      if(res.data.data.results.length ==0){
          this.finished =true
      }
    },
  },
};
</script>

<style lang="less">
.result-container {
  height: 100vh;
  padding-top: 46px;
  box-sizing: border-box;
  .search-list {
    height: 100%;
    overflow-y: scroll;
  }
}
</style>